package com.ftg.learn.lesson3;

import java.util.Scanner;

/**
 * 练习
 *
 * @author kangjx
 * @version 1.0
 * @date 2023/6/6 上午8:46
 */
public class LearnLoop2 {

    // 1 2 3 4 5 6 7 8 9

    // 2 4 6 8 10

    // 1 3 5 7 9

    // 1 2 3 4 5 4 3 2 1

    public static void main(String[] args) {

        System.out.println("使用第二个变量 ");
        for (int i = 1, j = 5; i < 10; i++) {
            if (i <= 5) {
                System.out.print(i + "\t");
            } else {
                System.out.print(--j + "\t");
            }
        }
        System.out.println();

        System.out.println("代码多");
        for (int i = 1; i < 10; i++) {
            if (i <= 5) {
                System.out.print(i + "\t");
            } else {
                System.out.print(10 - i + "\t");
            }
        }
        System.out.println();

        System.out.println("比较简单");
        for (int i = 1; i < 10; i++) {
            System.out.print((i <= 5 ? i : 10 - i) + "\t");
        }
        System.out.println();

        System.out.println("新题1");
        for (int i = 2; i < 16; i += 2) {
            System.out.print((i <= 8 ? i : 16 - i) + "\t");
        }
        System.out.println();

        System.out.println("i是倍数");
        for (int i = 1; i < 8; i++) {
            System.out.print((i <= 8 >> 1 ? 2 * i : 2 * 8 - 2 * i) + "\t");
        }
        System.out.println();

        System.out.println("----2");
        for (int i = 0, x = 1, y = 10; i < 5; i++, x += 2, y -= 2) {
            System.out.print(x + "\t" + y + "\t");
        }
        System.out.println();

        System.out.println("----2");
        for (int x = 1, y = 10; y >= 2 && x <= 9; x += 2, y -= 2) {
            System.out.print(x + "\t" + y + "\t");
        }
        System.out.println();

//        int x = 12321 ;
        //回文数 12321
//       2345
//        int n = (int)Math.pow(10,0);
//        x  / 1   % 10
//        x  /10   %  10
//        x  /100  %10
//        x  /1000 %10


        Scanner scanner = new Scanner(System.in);
        System.out.println("请输入一个正整数");

        int x = scanner.nextInt();
        int index = 0;
        for (int y = x; y > 0; y /= 10) {
            index++;
        }

        boolean ist = true;
        for (int i = 0, j = index; i < j; i++, j--) {
            int f = x / (int) Math.pow(10, i) % 10;
            int s = x / (int) Math.pow(10, j-1) % 10;
            if(f != s){
                ist = false;
                break;
            }
        }

        System.out.println(ist ?"是回文 ":"不是");

    }


    //可以if   试三目

    // 2 4 6 8 6 4 2

    // 1 10 3 8 5 6 7 4 9 2
}
